using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace _42_Kicks
{
   
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        Texture2D personnage; 
        //float speed;
        Rectangle source;
        Rectangle destination;
        TimeSpan temps;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            //this.graphics.ToggleFullScreen();
            //speed = 1f;
            IsMouseVisible = true;
            
        }
        public Vector2 position
        {
            get { return position; }
            set { position = value; }
        }
        protected override void Initialize()
        {
            destination = new Rectangle(200, 370, 39, 80);
            source = new Rectangle(0, 0, 39, 80);
            personnage = this.Content.Load<Texture2D>("marche");
            base.Initialize();
        }
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            
        }
        protected override void UnloadContent()
        {
        }
        protected override void Update(GameTime gameTime)
        {
            KeyboardState KState = Keyboard.GetState();

            if (KState.IsKeyDown(Keys.Left))
            {
                if (gameTime.TotalGameTime.Subtract(temps).Milliseconds >= 190)
                {
                   if (source.X < 156)
                    { source.X = 156; }
                   destination.X -= 11;
                    source.X = (source.X > 273) ? 157 : source.X + 40;
                    temps = gameTime.TotalGameTime;
                    //destination.X -= 12;
                    
                    
                    
                }
            }

            if (KState.IsKeyDown(Keys.Right))
            {

                if (gameTime.TotalGameTime.Subtract(temps).Milliseconds >= 190)
                {
                    destination.X += 11;
                    source.X = (source.X > 116) ? 0 : source.X + source.Width;
                    temps = gameTime.TotalGameTime;
                    //destination.X += 12;
                }
            }
            


            base.Update(gameTime);
        }
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CadetBlue);
            spriteBatch.Begin();

            spriteBatch.Draw(personnage, destination, source, Color.White);
            
            spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}